package com.zzyl.serve.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzyl.serve.domain.Device;
import com.zzyl.serve.vo.FamilyPageVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * 设备管理Mapper接口
 * 
 * @author liuyp
 * @date 2025-08-22
 */
@Mapper
public interface DeviceMapper extends BaseMapper<Device>
{
    /**
     * 查询设备管理
     * 
     * @param id 设备管理主键
     * @return 设备管理
     */
    public Device selectDeviceById(Long id);

    /**
     * 查询设备管理列表
     * 
     * @param device 设备管理
     * @return 设备管理集合
     */
    public List<Device> selectDeviceList(Device device);

    /**
     * 新增设备管理
     * 
     * @param device 设备管理
     * @return 结果
     */
    public int insertDevice(Device device);

    /**
     * 修改设备管理
     * 
     * @param device 设备管理
     * @return 结果
     */
    public int updateDevice(Device device);

    /**
     * 删除设备管理
     * 
     * @param id 设备管理主键
     * @return 结果
     */
    public int deleteDeviceById(Long id);

    /**
     * 批量删除设备管理
     * 
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteDeviceByIds(Long[] ids);

    @Select("select ne.nursing_id from device d " +
            "    left join bed b on d.binding_location = b.id " +
            "    left join elder e on e.bed_id = b.id " +
            "    left join nursing_elder ne on ne.elder_id = e.id " +
            "where d.iot_id = #{iotId}")
    Set<Long> selectNurseIdsByBedIotId(String iotId);

    @Select("select fe.id as mid,fe.remark as mremark,d.iot_id,e.name,e.image,e.bed_number,r.type_name,d.device_name,d.product_key from device d\n" +
            "    join elder e on d.binding_location = e.id and location_type = 0\n" +
            "    left join bed b on e.bed_id = b.id\n" +
            "    left join room r on b.room_id = r.id\n" +
            "    join family_member_elder fe on e.id = fe.elder_id\n" +
            " ")
    List<FamilyPageVo> selectElder();
}
